﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using ChangeHope.Common;
using System.Data;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        /// <summary>
        /// 用户有关的标签解析
        /// </summary>
        /// <returns></returns>
        public string Member()
        {
            string mystyle = this.Label_Inserted;
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            string Option = this.GetParamValue("YX:Option");//判断操作类型

            #region 注册表单
            if (Option == "MemberRegForm")
            {
                string strFormContent = mystyle;
                #region 固定样式
                //账号
                if (strFormContent.IndexOf("[#form_userid]") > -1)
                {
                    StringBuilder strUserID = new StringBuilder();
                    strUserID.Append("<input id=\"regusername\" onblur=\"onName()\" name=\"regusername\" style=\"width:150px; height:20px\" size=\"20\"  />\n");
                    strUserID.Append("<span id=\"spname\" style=\"margin-left: 20px; COLOR: #666666\">6-20位字符，可由中英文、数字及&ldquo;_&rdquo;、&ldquo;-&rdquo;组成</span>\n");
                    strFormContent = strFormContent.Replace("[#form_userid]", strUserID.ToString());
                }

                //密码
                if (strFormContent.IndexOf("[#form_pwd]") > -1)
                {
                    StringBuilder strPwd = new StringBuilder();
                    strPwd.Append("<input  id=\"reguserpwd\" onblur=\"onuserpwd()\" type=\"password\" name=\"reguserpwd\" style=\"width:150px; height:20px\" size=\"20\" />\n");
                    strPwd.Append("<span id=\"sppwd\" style=\"margin-left: 20px; COLOR: #666666\">6-16位字符，可由英文、数字及\"_\"、\"-\"组成</span>\n");
                    strFormContent = strFormContent.Replace("[#form_pwd]", strPwd.ToString());
                }

                //确认密码
                if (strFormContent.IndexOf("[#form_repwd]") > -1)
                {
                    StringBuilder strRePwd = new StringBuilder();
                    strRePwd.Append("<input id=\"regrepwd\" onblur=\"onRepwd()\" type=\"password\" name=\"regrepwd\" style=\"width:150px; height:20px\" size=\"20\" />\n");
                    strRePwd.Append("<span id=\"sprepwd\" style=\"margin-left: 20px; COLOR: #666666\"></span>\n");
                    strFormContent = strFormContent.Replace("[#form_repwd]", strRePwd.ToString());
                }

                //密保问题
                if (strFormContent.IndexOf("[#form_question]") > -1)
                {
                    StringBuilder strQues = new StringBuilder();
                    strQues.Append("<select class=\"hw\" id=\"question\" title=\"密码保护问题\" name=\"question\"  onchange=\"getindex();\">\n");
                    strQues.Append("<option value=\"\" selected=\"selected\">请选择一个问题</option>\n");              
                    strQues.Append("<option value=\"我就读的第一所学校的名称？\">我就读的第一所学校的名称？</option>\n");
                    strQues.Append("<option value=\"我最喜欢的休闲运动是什么？\">我最喜欢的休闲运动是什么？</option>\n");
                    strQues.Append("<option value=\"我最喜欢的运动员是谁？\">我最喜欢的运动员是谁？</option>\n");
                    strQues.Append("<option value=\"我最喜欢的物品的名称？\">我最喜欢的物品的名称？</option>\n");
                    strQues.Append("<option value=\"我最喜欢的歌曲？\">我最喜欢的歌曲？</option>\n");
                    strQues.Append("<option value=\"我最喜欢的食物？\">我最喜欢的食物？</option>\n");
                    strQues.Append("<option value=\"我最爱的人的名字？\">我最爱的人的名字？</option>\n");
                    strQues.Append("<option value=\"我最爱的电影？\">我最爱的电影？</option>\n");
                    strQues.Append("<option value=\"我妈妈的生日？\">我妈妈的生日？</option>\n");
                    strQues.Append("<option value=\"我的初恋日期？\">我的初恋日期？</option>\n");
                    strQues.Append("</select></label>\n");
                    strQues.Append("<input type=\"hidden\" value=\"1\" name=\"hfQuestion\" />\n");
                    strQues.Append(" <span id=\"spquestion\" style=\"margin-left: 20px; COLOR: #666666\"></span>\n");
                    strFormContent = strFormContent.Replace("[#form_question]", strQues.ToString());
                }

                //密保答案
                if (strFormContent.IndexOf("[#form_answer]") > -1)
                {
                    StringBuilder strAns = new StringBuilder();
                    strAns.Append("<input id=\"insolution\" onblur=\"oninsolution()\" name=\"insolution\" style=\"width:150px; height:20px\" size=\"30\"/>\n");
                    strAns.Append("<span id=\"spinsolution\" style=\"margin-left: 20px; COLOR: #666666\">3-30位字符，可由中英文组成</span>\n");
                    strFormContent = strFormContent.Replace("[#form_answer]", strAns.ToString());
                }

                //Email
                if (strFormContent.IndexOf("[#form_email]") > -1)
                {
                    StringBuilder strEmail = new StringBuilder();
                    strEmail.Append("<input id=\"Email\" onblur=\"onEmail()\" name=\"Email\" style=\"width:150px; height:20px\"  />\n");
                    strEmail.Append("<span id=\"spEmail\" style=\"margin-left: 20px; COLOR: #666666\"></span>\n");
                    strFormContent = strFormContent.Replace("[#form_email]", strEmail.ToString());
                }

                //同意checkbox
                if (strFormContent.IndexOf("[#form_agree]") > -1)
                {
                    StringBuilder strAgree = new StringBuilder();
                    strAgree.Append("<input id=\"cbagreement\" type=\"checkbox\" checked=\"checked\" name=\"cbagreement\" value=\"on\" /></label>\n");
                    string url = YXShop.TemplateAction.Common.UrlStr("agreement", "", "membercenter/");
                    strAgree.Append("我已阅读并同意《<a target=\"_blank\" href=\"" + url + "\">商城服务条款</a>》\n");
                    strAgree.Append("<br /><br /><span id=\"spment\" style=\"margin-left: 20px; COLOR: #666666\"></span>\n");
                    strFormContent = strFormContent.Replace("[#form_agree]", strAgree.ToString());
                }

                //提交
                if (strFormContent.IndexOf("[#form_submit]") > -1)
                {
                    strFormContent = strFormContent.Replace("[#form_submit]", "<label><input id=\"button\" type=\"submit\" name=\"button\" value=\" 注 册 \" /> </label>\n");
                }
                #endregion

                #region 可选样式
                //真实姓名
                if (strFormContent.IndexOf("[#form_realname]") > -1)
                {
                    StringBuilder strRealName= new StringBuilder();
                    strRealName.Append("<input  id=\"txtRealName\"  name=\"txtRealName\" style=\"width:150px; height:20px\" />\n");
                    strFormContent = strFormContent.Replace("[#form_realname]", strRealName.ToString());
                }

                //固定电话
                if (strFormContent.IndexOf("[#form_tel]") > -1)
                {
                    StringBuilder strTel = new StringBuilder();
                    strTel.Append("<input  id=\"txtTel\"  name=\"txtTel\" style=\"width:150px; height:20px\" />\n");
                    strFormContent = strFormContent.Replace("[#form_tel]", strTel.ToString());
                }

                //公司地址
                if (strFormContent.IndexOf("[#form_companyaddress]") > -1)
                {
                    StringBuilder strAddress = new StringBuilder();
                    strAddress.Append("<input id=\"txtAddress\"  name=\"txtAddress\" style=\"width:150px; height:20px\" />\n");
                    strFormContent = strFormContent.Replace("[#form_companyaddress]", strAddress.ToString());
                }

                //MSN
                if (strFormContent.IndexOf("[#form_msn]") > -1)
                {
                    StringBuilder strMsn = new StringBuilder();
                    strMsn.Append("<input id=\"txtMsn\"  name=\"txtMsn\" style=\"width:150px; height:20px\" />\n");
                    strFormContent = strFormContent.Replace("[#form_msn]", strMsn.ToString());
                }

                //街道地址
                if (strFormContent.IndexOf("[#form_street]") > -1)
                {
                    StringBuilder strStreet = new StringBuilder();
                    strStreet.Append("<input id=\"txtStreet\"  name=\"txtStreet\" style=\"width:150px; height:20px\" />\n");
                    strFormContent = strFormContent.Replace("[#form_street]", strStreet.ToString());
                }

                //传真
                if (strFormContent.IndexOf("[#form_fax]") > -1)
                {
                    StringBuilder strFax = new StringBuilder();
                    strFax.Append("<input id=\"txtFax\"  name=\"txtFax\" style=\"width:150px; height:20px\"  />\n");
                    strFormContent = strFormContent.Replace("[#form_fax]", strFax.ToString());
                }

                //手机
                if (strFormContent.IndexOf("[#form_mobile]") > -1)
                {
                    StringBuilder strFax = new StringBuilder();
                    strFax.Append("<input id=\"txtMobile\"  name=\"txtMobile\" style=\"width:150px; height:20px\"  />\n");
                    strFormContent = strFormContent.Replace("[#form_mobile]", strFax.ToString());
                }

                //邮编
                if (strFormContent.IndexOf("[#form_zipcode]") > -1)
                {
                    StringBuilder strFax = new StringBuilder();
                    strFax.Append("<input id=\"txtZip\"  name=\"txtZip\" style=\"width:150px; height:20px\" />\n");
                    strFormContent = strFormContent.Replace("[#form_zipcode]", strFax.ToString());
                }

                //公司名称
                if (strFormContent.IndexOf("[#form_companyname]") > -1)
                {
                    StringBuilder strCName = new StringBuilder();
                    strCName.Append("<input id=\"txtCname\"  name=\"txtCname\" style=\"width:150px; height:20px\"  />\n");
                    strFormContent = strFormContent.Replace("[#form_companyname]", strCName.ToString());
                }

                //职位
                if (strFormContent.IndexOf("[#form_post]") > -1)
                {
                    StringBuilder strCName = new StringBuilder();
                    strCName.Append("<input id=\"txtPost\"  name=\"txtPost\" style=\"width:150px; height:20px\" />\n");
                    strFormContent = strFormContent.Replace("[#form_post]", strCName.ToString());
                }

                //验证码 
                if (strFormContent.IndexOf("[#ValidateCode]") > -1)
                {
                    StringBuilder strValCode = new StringBuilder();
                    strValCode.Append("<input type=\"text\" name=\"txtCode\" id=\"txtCode\" style=\" width:50px;height:20px \"/>&nbsp;&nbsp;<img alt=\"点击刷新验证码\" onclick=\"this.src='" + sp.DummyPaht + "admin/plugin/check_code.aspx?rdm='+Math.random();\" src=\"" + sp.DummyPaht + "admin/plugin/check_code.aspx\" class=\"pointer\"/>\n");
                    strFormContent = strFormContent.Replace("[#ValidateCode]", strValCode.ToString());
                }
                #endregion


                return strFormContent;
            }
            #endregion

            #region 用户注册协议
            else if (Option == "MemberAgree")
            {
                string strAgree = mystyle;
                //职位
                if (strAgree.IndexOf("[#form_agree]") > -1)
                {
                    YXShop.BLL.SystemInfo.WebSetting bll = new YXShop.BLL.SystemInfo.WebSetting();
                    YXShop.Model.SystemInfo.WebSetting model = null;
                    try
                    {
                        model = bll.GetModel();
                        if(model!=null)
                        {
                            strAgree = strAgree.Replace("[#form_agree]", model.UsersAgreement);
                        }
                    }
                    catch { }
                    finally
                    {
                        model = null;
                    }
                    
                }
                return strAgree;
            }
            #endregion
            else
            {
                return "无法找到标签";
            }
        }
    }
}


